package com.housekeeping.housekeeping.administrator.adminsinformation.dao.impl;

import com.housekeeping.housekeeping.administrator.adminsinformation.dao.NewDao;
import com.housekeeping.housekeeping.administrator.entity.AdminsInformation;
import com.housekeeping.housekeeping.administrator.utils.Dbmanage;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class NewDaoImpl implements NewDao {
    @Override
    public String newafter(AdminsInformation admins) {
        Connection connection=null;
        PreparedStatement statement=null;
        String jurisdiction=null;
        try {
            connection= Dbmanage.getConnection();
            String sql="update admins_information set name=?,account=?,password=?,phone_number=?,jurisdiction=?,remark=? where id=?";
            statement=connection.prepareStatement(sql);
            statement.setString(1,admins.getName()+"");
            statement.setString(2,admins.getAccount()+"");
            statement.setString(3,admins.getPassword()+"");
            statement.setString(4,admins.getPhoneNumber()+"");
            statement.setString(5,admins.getJurisdiction()+"");
            statement.setString(6,admins.getRemark()+"");
            statement.setInt(7,admins.getId());
             int count=statement.executeUpdate();
             if (count>0){
                 jurisdiction=admins.getJurisdiction();
             }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            Dbmanage.close(connection,statement);
        }
        return jurisdiction;
    }
}
